package net.area80.fbx.utils
{
		public class Quaternion {
			private var $y:Number;
			private var $z:Number;
			private var $w:Number;
			private var $x:Number;
			
			public function Quaternion(a:Number, b:Number, c:Number, d:Number) {
				$x = a ? a : 0;
				$y = b ? b : 0;
				$z = c ? c : 0;
				$w = d ? d : 1;
			}
			
			public function get x():Number {
				return $x;
			}
			
			public function get y():Number {
				return $y;
			}
			
			public function get z():Number {
				return $z;
			}
		
			public function get w():Number {
				return $w;
			}
		
			public function fromPoint(a:Number, b:Number, c:Number):void {
				$x = a;
				$y = b;
				$z = c;
				$w = 0;
			}
						
		  	public function fromAxisAngle(a:Number, b:Number, c:Number, d:Number):void {
				var ca = Math.cos(d/2); var sa = Math.sin(d/2);
				var m = Math.sqrt(a*a + b*b + c*c);
				$x = a/m * sa;
				$y = b/m * sa;
				$z = c/m * sa;
				$w = ca;
			}
						
			public function concat(q:Quaternion):void {
				var w1 = $w; var x1 = $x; var y1 = $y; var z1 = $z;
				var w2 = q.w; var x2 = q.x; var y2 = q.y; var z2 = q.z;
				$w = w1*w2 - x1*x2 - y1*y2 - z1*z2
				$x = w1*x2 + x1*w2 + y1*z2 - z1*y2
				$y = w1*y2 + y1*w2 + z1*x2 - x1*z2
				$z = w1*z2 + z1*w2 + x1*y2 - y1*x2
			}
			
			public function invert():void {
				$x = -$x;
				$y = -$y;
				$z = -$z;
			}
		
			public function copy():Quaternion {
				return new Quaternion($x, $y, $z, $w);
			}
		}
}